#ifndef _SYNTAX_H
#define _SYNTAX_H

#include "tokenizer.h"



struct syntax_element_t;

struct syntax_leaf_t {
	struct token_t* token;
};

struct syntax_node_t {
	int num_children;
	struct syntax_element_t** children;
};

enum syntax_element_type {TYPE_LEAF = 0, TYPE_NODE_OR, TYPE_NODE_AND};

struct syntax_element_t {
	enum syntax_element_type type;
	union {
		struct syntax_node_t node;
		struct syntax_leaf_t leaf;
	};
};

struct path_element_t {
	int current;
	struct syntax_element_t* element;
	struct path_element_t *prev, *next;
};

struct syntax_t {
	struct syntax_element_t* root;
	struct list_t* elements;
};

int syntax_add(struct syntax_element_t* se);
struct syntax_element_t* create_leaf(struct token_t* token);
struct syntax_element_t* create_or_node(int num_children);
struct syntax_element_t* create_and_node(int num_children);
void add_to_node(struct syntax_element_t* parent, struct syntax_element_t* child, int num);
int syntax_init_root(struct syntax_t* syntax, struct syntax_element_t* root);
void syntax_free(struct syntax_t* syntax);

#endif

